package com.team.lostProperty.service.impl;

import com.team.lostProperty.entity.Comments;
import com.team.lostProperty.entity.LikeMap;
import com.team.lostProperty.entity.PushInfo;
import com.team.lostProperty.entity.User;
import com.team.lostProperty.mapper.CommentsDao;
import com.team.lostProperty.service.CommentsService;
import com.team.lostProperty.service.NewPushInfoService;
import com.team.lostProperty.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author kittlen
 * @version 1.0
 * @date 2020/7/22 19:02
 */

@Service
public class CommentsServiceImpl implements CommentsService {

    @Resource
    private CommentsDao commentsDao;
    @Resource
    private NewPushInfoService newPushInfoService;

    @Override
    public int getAllCount(int status) {
        return commentsDao.getAllCount(status);
    }

    @Override
    public List<Comments> getComments(int status, int page, int limit) {
        int start = (page-1) * limit;
        return commentsDao.getComments(status, start, limit);
    }

    @Override
    public List<Comments> selectComments(Comments comments) {
        return commentsDao.selectComments(comments);
    }

    @Override
    public int deleteComments(int id) {
        return commentsDao.deleteComments(id);
    }

    @Override
    public int updateComments(int status, long commentsId) {
        return commentsDao.updateComments(status, commentsId);
    }

    @Override
    public List<Comments> selectByPushInfoId(Long pushInfoId) {
        return commentsDao.selectByPushInfoId(pushInfoId);
    }

    @Override
    public Comments insertComment(long userId, long pushInfoId, String createdDate,String content) {
        IdWorker idWorker = new IdWorker(1, 1, 1);
        long commentId = idWorker.nextId();
        System.out.println(commentId);
        User user = new User();
        user.setUserId(userId);
        PushInfo pushInfo = new PushInfo();
        pushInfo.setPushInfoId(pushInfoId);
        Comments comments = new Comments();
        comments.setCommentsId(commentId);
        comments.setUser(user);
        comments.setPushInfo(pushInfo);
        comments.setCreatedDate(createdDate);
        comments.setContent(content);
        comments.setStatus(0);
        try {
            commentsDao.insertComment(comments);
            return comments;
        }catch (Exception e){

        }
        return null;
    }
}
